/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.fatecpg.mobileinstrumento;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author Nelson
 */
public class HelloMIDlet extends MIDlet implements CommandListener, ItemStateListener {

    private boolean midletPaused = false;
//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Command calcularCommand;
    private Command rangeExitCommand;
    private Command rangeCommand;
    private Command limparCommand;
    private Command pressaoExitCommand;
    private Command pressaoCommand;
    private Command exitCommand;
    private Command temperaturaExitCommand;
    private Command temperaturaCommand;
    private Form formRange;
    private TextField valorRangeInferiorTextField;
    private TextField valorRangeTextField;
    private StringItem resultadoAmperStringItem;
    private TextField valorRangeSuperiorTextField;
    private StringItem resultadoPsiStringItem;
    private Form formPressão;
    private ChoiceGroup unidadeInPressaoChoiceGroup;
    private TextField pressaoTextField;
    private StringItem resultadoPressaoStringItem;
    private ChoiceGroup unidadeOutPressaoChoiceGroup;
    private Form formPrincipal;
    private StringItem stringItem;
    private Form formTemperatura;
    private ChoiceGroup unidadeInTemperaturaChoiceGroup;
    private TextField temperaturaTextField;
    private StringItem resultadoTemperaturaStringItem;
    private ChoiceGroup unidadeOutTemperaturaChoiceGroup;
//</editor-fold>//GEN-END:|fields|0|

    /**
     * The HelloMIDlet constructor.
     */
    public HelloMIDlet() {
    }

//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
//</editor-fold>//GEN-END:|methods|0|
//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initializes the application. It is called only once when the MIDlet is
     * started. The method is called before the
     * <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
//</editor-fold>//GEN-END:|0-initialize|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getFormPrincipal());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
//</editor-fold>//GEN-END:|3-startMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
//</editor-fold>//GEN-END:|4-resumeMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The
     * <code>display</code> instance is taken from
     * <code>getDisplay</code> method. This method is used by all actions in the
     * design for switching displayable.
     *
     * @param alert the Alert which is temporarily set to the display;
     * if <code>null</code>, then <code>nextDisplayable</code> is set
     * immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
//</editor-fold>//GEN-END:|5-switchDisplayable|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a
     * particular displayable.
     *
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == formPressão) {//GEN-BEGIN:|7-commandAction|1|43-preAction
            if (command == pressaoExitCommand) {//GEN-END:|7-commandAction|1|43-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormPrincipal());//GEN-LINE:|7-commandAction|2|43-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|74-preAction
        } else if (displayable == formPrincipal) {
            if (command == exitCommand) {//GEN-END:|7-commandAction|3|74-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|4|74-postAction
                // write post-action user code here
            } else if (command == pressaoCommand) {//GEN-LINE:|7-commandAction|5|77-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormPressão());//GEN-LINE:|7-commandAction|6|77-postAction
                // write post-action user code here
            } else if (command == rangeCommand) {//GEN-LINE:|7-commandAction|7|136-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormRange());//GEN-LINE:|7-commandAction|8|136-postAction
                // write post-action user code here
            } else if (command == temperaturaCommand) {//GEN-LINE:|7-commandAction|9|83-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormTemperatura());//GEN-LINE:|7-commandAction|10|83-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|11|144-preAction
        } else if (displayable == formRange) {
            if (command == calcularCommand) {//GEN-END:|7-commandAction|11|144-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|12|144-postAction
                // write post-action user code here
                try {
                    double resultadoPor;
                   
                    double resultadoAmper;
                    double resultadPsi;
                    double baixa = Double.parseDouble(valorRangeInferiorTextField.getString());
                    double alta = Double.parseDouble(valorRangeSuperiorTextField.getString());
                    double valorRange = Double.parseDouble(valorRangeTextField.getString());
                    double spanRange = alta - baixa;
                    resultadoPor = Math.abs(((valorRange-baixa)*100)/spanRange);
                    resultadPsi=((12*resultadoPor)/100)+3;
                    resultadoAmper=((16*resultadoPor)/100)+4;

                    if (resultadPsi < 3) {
                        resultadoPsiStringItem.setText("Valor abaixo da faixa.");;
                    } else if (resultadPsi > 15) {
                        resultadoPsiStringItem.setText("Valor acima da faixa.");
                    } else {
                        resultadoPsiStringItem.setText(Double.toString(resultadPsi) + " Psi");
                    }
                    if (resultadoAmper < 4) {
                        resultadoAmperStringItem.setText("Valor abaixo da faixa.");
                    } else if (resultadoAmper > 20) {
                        resultadoAmperStringItem.setText("Valor acima da faixa.");
                    } else {
                        resultadoAmperStringItem.setText(Double.toString(resultadoAmper) + " mA");
                    }
                    
                } catch (Exception e) {
                    resultadoPsiStringItem.setText("-");
                    resultadoAmperStringItem.setText("-");

                }





            } else if (command == limparCommand) {//GEN-LINE:|7-commandAction|13|146-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|14|146-postAction
                // write post-action user code here
                valorRangeInferiorTextField.setString(null);
                valorRangeSuperiorTextField.setString(null);
                valorRangeTextField.setString(null);
                resultadoAmperStringItem.setText(null);
                resultadoPsiStringItem.setText(null);
            } else if (command == rangeExitCommand) {//GEN-LINE:|7-commandAction|15|133-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormPrincipal());//GEN-LINE:|7-commandAction|16|133-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|17|81-preAction
        } else if (displayable == formTemperatura) {
            if (command == temperaturaExitCommand) {//GEN-END:|7-commandAction|17|81-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormPrincipal());//GEN-LINE:|7-commandAction|18|81-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|7-postCommandAction
        }//GEN-END:|7-commandAction|19|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|20|
//</editor-fold>//GEN-END:|7-commandAction|20|

    public void itemStateChanged(Item i) {
        try {
            double pressao = Double.parseDouble(pressaoTextField.getString());
            double r = 0;
            if (unidadeInPressaoChoiceGroup.isSelected(0)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 14.233;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.9807;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 28.95;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 393.83;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.9678;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 735.58;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 10003;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 98.0665;
                }

            } else if (unidadeInPressaoChoiceGroup.isSelected(1)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 0.0703;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.0689;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 2.036;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 27.689;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.068;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 51.71;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 70329;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 6.895;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(2)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 1.0197;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 14.504;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 29.53;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 401.6;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.98692;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 750.06;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 10200;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 100;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(3)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 0.0345;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 0.4911;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.03386;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 13.599;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.0334;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 25.399;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 345.40;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 3.3863;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(4)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 0.002537;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 0.03609;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.00249;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 0.07348;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.002456;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 1.8665;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 25.399;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 0.24884;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(5)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 1.0332;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 14.696;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 1.0133;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 29.921;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 406.933;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 706.05;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 10335;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 101.325;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(6)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 0.00135;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 0.019337;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.00133;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 0.03937;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 0.5354;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.001316;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 13.598;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 0.013332;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(7)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 0.000099;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 0.00142;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.00098;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 0.00289;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 0.03937;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.00009;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 0.07353;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 1;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 0.0098;
                }
            } else if (unidadeInPressaoChoiceGroup.isSelected(8)) {
                if (unidadeOutPressaoChoiceGroup.isSelected(0)) {
                    r = pressao * 0.010197;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(1)) {
                    r = pressao * 0.14504;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(2)) {
                    r = pressao * 0.01;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(3)) {
                    r = pressao * 0.29539;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(4)) {
                    r = pressao * 4.0158;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(5)) {
                    r = pressao * 0.009869;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(6)) {
                    r = pressao * 7.50062;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(7)) {
                    r = pressao * 101.998;
                } else if (unidadeOutPressaoChoiceGroup.isSelected(8)) {
                    r = pressao * 1;
                }
            }

            resultadoPressaoStringItem.setText(Double.toString(r));
        } catch (Exception e) {
            resultadoPressaoStringItem.setText("-");

        }
        try {
            double temperatura = Double.parseDouble(temperaturaTextField.getString());
            double r = 0;
            if (unidadeInTemperaturaChoiceGroup.isSelected(0)) {
                if (unidadeOutTemperaturaChoiceGroup.isSelected(0)) {
                    r = temperatura * 1;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(1)) {
                    r = (((temperatura - 32) / 9) * 5) + 273.15;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(2)) {
                    r = (((temperatura - 32) / 9) * 9) + 491.67;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(3)) {
                    r = ((temperatura - 32) / 9) * 5;
                }
            } else if (unidadeInTemperaturaChoiceGroup.isSelected(1)) {
                if (unidadeOutTemperaturaChoiceGroup.isSelected(0)) {
                    r = (((temperatura - 273.15) / 5) * 9) + 32;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(1)) {
                    r = temperatura * 1;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(2)) {
                    r = (((temperatura - 273.15) / 5) * 9) + 491.67;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(3)) {
                    r = (((temperatura - 273.15) / 5) * 5);
                }
            } else if (unidadeInTemperaturaChoiceGroup.isSelected(2)) {
                if (unidadeOutTemperaturaChoiceGroup.isSelected(0)) {
                    r = (((temperatura - 491.67) / 9) * 9) + 32;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(1)) {
                    r = (((temperatura - 491.67) / 9) * 5) + 273.15;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(2)) {
                    r = temperatura * 1;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(3)) {
                    r = (((temperatura - 491.67) / 9) * 5);
                }
            } else if (unidadeInTemperaturaChoiceGroup.isSelected(3)) {
                if (unidadeOutTemperaturaChoiceGroup.isSelected(0)) {
                    r = ((temperatura / 5) * 9) + 32;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(1)) {
                    r = ((temperatura / 5) * 5) + 273.15;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(2)) {
                    r = ((temperatura / 5) * 9) + 491.67;
                } else if (unidadeOutTemperaturaChoiceGroup.isSelected(3)) {
                    r = temperatura * 1;
                }
            }

            resultadoTemperaturaStringItem.setText(Double.toString(r));
        } catch (Exception e) {
            resultadoTemperaturaStringItem.setText("-");

        }
    }

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: pressaoExitCommand ">//GEN-BEGIN:|42-getter|0|42-preInit
    /**
     * Returns an initialized instance of pressaoExitCommand component.
     *
     * @return the initialized component instance
     */
    public Command getPressaoExitCommand() {
        if (pressaoExitCommand == null) {//GEN-END:|42-getter|0|42-preInit
            // write pre-init user code here
            pressaoExitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|42-getter|1|42-postInit
            // write post-init user code here
        }//GEN-BEGIN:|42-getter|2|
        return pressaoExitCommand;
    }
//</editor-fold>//GEN-END:|42-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: formPressão ">//GEN-BEGIN:|33-getter|0|33-preInit
    /**
     * Returns an initialized instance of formPressão component.
     *
     * @return the initialized component instance
     */
    public Form getFormPressão() {
        if (formPressão == null) {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            formPressão = new Form("Conversor de Press\u00E3o", new Item[]{getPressaoTextField(), getUnidadeInPressaoChoiceGroup(), getUnidadeOutPressaoChoiceGroup(), getResultadoPressaoStringItem()});//GEN-BEGIN:|33-getter|1|33-postInit
            formPressão.addCommand(getPressaoExitCommand());
            formPressão.setCommandListener(this);//GEN-END:|33-getter|1|33-postInit
            // write post-init user code here
            formPressão.setItemStateListener(this);
        }//GEN-BEGIN:|33-getter|2|
        return formPressão;
    }
//</editor-fold>//GEN-END:|33-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: pressaoTextField ">//GEN-BEGIN:|45-getter|0|45-preInit
    /**
     * Returns an initialized instance of pressaoTextField component.
     *
     * @return the initialized component instance
     */
    public TextField getPressaoTextField() {
        if (pressaoTextField == null) {//GEN-END:|45-getter|0|45-preInit
            // write pre-init user code here
            pressaoTextField = new TextField("Press\u00E3o", "", 32, TextField.DECIMAL);//GEN-LINE:|45-getter|1|45-postInit
            // write post-init user code here
        }//GEN-BEGIN:|45-getter|2|
        return pressaoTextField;
    }
//</editor-fold>//GEN-END:|45-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: unidadeInPressaoChoiceGroup ">//GEN-BEGIN:|46-getter|0|46-preInit
    /**
     * Returns an initialized instance of unidadeInPressaoChoiceGroup component.
     *
     * @return the initialized component instance
     */
    public ChoiceGroup getUnidadeInPressaoChoiceGroup() {
        if (unidadeInPressaoChoiceGroup == null) {//GEN-END:|46-getter|0|46-preInit
            // write pre-init user code here
            unidadeInPressaoChoiceGroup = new ChoiceGroup("Unidades de Press\u00E3o", Choice.EXCLUSIVE);//GEN-BEGIN:|46-getter|1|46-postInit
            unidadeInPressaoChoiceGroup.append("Kgf/cm\u00B2", null);
            unidadeInPressaoChoiceGroup.append("Ibf/pol\u00B2", null);
            unidadeInPressaoChoiceGroup.append("BAR", null);
            unidadeInPressaoChoiceGroup.append("Pol Hg", null);
            unidadeInPressaoChoiceGroup.append("Pol H\u00B2O", null);
            unidadeInPressaoChoiceGroup.append("ATM", null);
            unidadeInPressaoChoiceGroup.append("mmHg", null);
            unidadeInPressaoChoiceGroup.append("mmH\u00B2O", null);
            unidadeInPressaoChoiceGroup.append("Kpa", null);
            unidadeInPressaoChoiceGroup.setSelectedFlags(new boolean[]{false, false, false, false, false, false, false, false, false});//GEN-END:|46-getter|1|46-postInit
            // write post-init user code here
        }//GEN-BEGIN:|46-getter|2|
        return unidadeInPressaoChoiceGroup;
    }
//</editor-fold>//GEN-END:|46-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: resultadoPressaoStringItem ">//GEN-BEGIN:|56-getter|0|56-preInit
    /**
     * Returns an initialized instance of resultadoPressaoStringItem component.
     *
     * @return the initialized component instance
     */
    public StringItem getResultadoPressaoStringItem() {
        if (resultadoPressaoStringItem == null) {//GEN-END:|56-getter|0|56-preInit
            // write pre-init user code here
            resultadoPressaoStringItem = new StringItem("Valor convertido:", "");//GEN-LINE:|56-getter|1|56-postInit
            // write post-init user code here
        }//GEN-BEGIN:|56-getter|2|
        return resultadoPressaoStringItem;
    }
//</editor-fold>//GEN-END:|56-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|73-getter|0|73-preInit
    /**
     * Returns an initialized instance of exitCommand component.
     *
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|73-getter|0|73-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|73-getter|1|73-postInit
            // write post-init user code here
        }//GEN-BEGIN:|73-getter|2|
        return exitCommand;
    }
//</editor-fold>//GEN-END:|73-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: pressaoCommand ">//GEN-BEGIN:|76-getter|0|76-preInit
    /**
     * Returns an initialized instance of pressaoCommand component.
     *
     * @return the initialized component instance
     */
    public Command getPressaoCommand() {
        if (pressaoCommand == null) {//GEN-END:|76-getter|0|76-preInit
            // write pre-init user code here
            pressaoCommand = new Command("Press\u00E3o", Command.ITEM, 0);//GEN-LINE:|76-getter|1|76-postInit
            // write post-init user code here
        }//GEN-BEGIN:|76-getter|2|
        return pressaoCommand;
    }
//</editor-fold>//GEN-END:|76-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: formPrincipal ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initialized instance of formPrincipal component.
     *
     * @return the initialized component instance
     */
    public Form getFormPrincipal() {
        if (formPrincipal == null) {//GEN-END:|69-getter|0|69-preInit
            // write pre-init user code here
            formPrincipal = new Form("Mobile Instrumento", new Item[]{getStringItem()});//GEN-BEGIN:|69-getter|1|69-postInit
            formPrincipal.addCommand(getExitCommand());
            formPrincipal.addCommand(getPressaoCommand());
            formPrincipal.addCommand(getTemperaturaCommand());
            formPrincipal.addCommand(getRangeCommand());
            formPrincipal.setCommandListener(this);//GEN-END:|69-getter|1|69-postInit
            // write post-init user code here
        }//GEN-BEGIN:|69-getter|2|
        return formPrincipal;
    }
//</editor-fold>//GEN-END:|69-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: temperaturaExitCommand ">//GEN-BEGIN:|80-getter|0|80-preInit
    /**
     * Returns an initialized instance of temperaturaExitCommand component.
     *
     * @return the initialized component instance
     */
    public Command getTemperaturaExitCommand() {
        if (temperaturaExitCommand == null) {//GEN-END:|80-getter|0|80-preInit
            // write pre-init user code here
            temperaturaExitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|80-getter|1|80-postInit
            // write post-init user code here
        }//GEN-BEGIN:|80-getter|2|
        return temperaturaExitCommand;
    }
//</editor-fold>//GEN-END:|80-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: temperaturaCommand ">//GEN-BEGIN:|82-getter|0|82-preInit
    /**
     * Returns an initialized instance of temperaturaCommand component.
     *
     * @return the initialized component instance
     */
    public Command getTemperaturaCommand() {
        if (temperaturaCommand == null) {//GEN-END:|82-getter|0|82-preInit
            // write pre-init user code here
            temperaturaCommand = new Command("Temperatura", Command.ITEM, 0);//GEN-LINE:|82-getter|1|82-postInit
            // write post-init user code here
        }//GEN-BEGIN:|82-getter|2|
        return temperaturaCommand;
    }
//</editor-fold>//GEN-END:|82-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: formTemperatura ">//GEN-BEGIN:|79-getter|0|79-preInit
    /**
     * Returns an initialized instance of formTemperatura component.
     *
     * @return the initialized component instance
     */
    public Form getFormTemperatura() {
        if (formTemperatura == null) {//GEN-END:|79-getter|0|79-preInit
            // write pre-init user code here
            formTemperatura = new Form("Conversor de Temperatura", new Item[]{getTemperaturaTextField(), getUnidadeInTemperaturaChoiceGroup(), getUnidadeOutTemperaturaChoiceGroup(), getResultadoTemperaturaStringItem()});//GEN-BEGIN:|79-getter|1|79-postInit
            formTemperatura.addCommand(getTemperaturaExitCommand());
            formTemperatura.setCommandListener(this);//GEN-END:|79-getter|1|79-postInit
            // write post-init user code here
            formTemperatura.setItemStateListener(this);
        }//GEN-BEGIN:|79-getter|2|
        return formTemperatura;
    }
//</editor-fold>//GEN-END:|79-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: temperaturaTextField ">//GEN-BEGIN:|109-getter|0|109-preInit
    /**
     * Returns an initialized instance of temperaturaTextField component.
     *
     * @return the initialized component instance
     */
    public TextField getTemperaturaTextField() {
        if (temperaturaTextField == null) {//GEN-END:|109-getter|0|109-preInit
            // write pre-init user code here
            temperaturaTextField = new TextField("Temperatura", "", 32, TextField.DECIMAL);//GEN-LINE:|109-getter|1|109-postInit
            // write post-init user code here
        }//GEN-BEGIN:|109-getter|2|
        return temperaturaTextField;
    }
//</editor-fold>//GEN-END:|109-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: unidadeInTemperaturaChoiceGroup ">//GEN-BEGIN:|110-getter|0|110-preInit
    /**
     * Returns an initialized instance of unidadeInTemperaturaChoiceGroup
     * component.
     *
     * @return the initialized component instance
     */
    public ChoiceGroup getUnidadeInTemperaturaChoiceGroup() {
        if (unidadeInTemperaturaChoiceGroup == null) {//GEN-END:|110-getter|0|110-preInit
            // write pre-init user code here
            unidadeInTemperaturaChoiceGroup = new ChoiceGroup("Unidade de Temperatura", Choice.EXCLUSIVE);//GEN-BEGIN:|110-getter|1|110-postInit
            unidadeInTemperaturaChoiceGroup.append("Fahrenheit", null);
            unidadeInTemperaturaChoiceGroup.append("Kelvin", null);
            unidadeInTemperaturaChoiceGroup.append("Rankine", null);
            unidadeInTemperaturaChoiceGroup.append("Celsius", null);
            unidadeInTemperaturaChoiceGroup.setSelectedFlags(new boolean[]{false, false, false, false});//GEN-END:|110-getter|1|110-postInit
            // write post-init user code here
        }//GEN-BEGIN:|110-getter|2|
        return unidadeInTemperaturaChoiceGroup;
    }
//</editor-fold>//GEN-END:|110-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: resultadoTemperaturaStringItem ">//GEN-BEGIN:|115-getter|0|115-preInit
    /**
     * Returns an initialized instance of resultadoTemperaturaStringItem
     * component.
     *
     * @return the initialized component instance
     */
    public StringItem getResultadoTemperaturaStringItem() {
        if (resultadoTemperaturaStringItem == null) {//GEN-END:|115-getter|0|115-preInit
            // write pre-init user code here
            resultadoTemperaturaStringItem = new StringItem("Valor convertido:", "");//GEN-LINE:|115-getter|1|115-postInit
            // write post-init user code here
        }//GEN-BEGIN:|115-getter|2|
        return resultadoTemperaturaStringItem;
    }
//</editor-fold>//GEN-END:|115-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: unidadeOutPressaoChoiceGroup ">//GEN-BEGIN:|116-getter|0|116-preInit
    /**
     * Returns an initialized instance of unidadeOutPressaoChoiceGroup
     * component.
     *
     * @return the initialized component instance
     */
    public ChoiceGroup getUnidadeOutPressaoChoiceGroup() {
        if (unidadeOutPressaoChoiceGroup == null) {//GEN-END:|116-getter|0|116-preInit
            // write pre-init user code here
            unidadeOutPressaoChoiceGroup = new ChoiceGroup("Unidade de Sa\u00EDda Press\u00E3o", Choice.EXCLUSIVE);//GEN-BEGIN:|116-getter|1|116-postInit
            unidadeOutPressaoChoiceGroup.append("Kgf/cm\u00B2", null);
            unidadeOutPressaoChoiceGroup.append("Ibf/pol\u00B2", null);
            unidadeOutPressaoChoiceGroup.append("BAR", null);
            unidadeOutPressaoChoiceGroup.append("Pol Hg", null);
            unidadeOutPressaoChoiceGroup.append("Pol H\u00B2O", null);
            unidadeOutPressaoChoiceGroup.append("ATM", null);
            unidadeOutPressaoChoiceGroup.append("mmHg", null);
            unidadeOutPressaoChoiceGroup.append("mmH\u00B2O", null);
            unidadeOutPressaoChoiceGroup.append("Kpa", null);
            unidadeOutPressaoChoiceGroup.setSelectedFlags(new boolean[]{false, false, false, false, false, false, false, false, false});//GEN-END:|116-getter|1|116-postInit
            // write post-init user code here
        }//GEN-BEGIN:|116-getter|2|
        return unidadeOutPressaoChoiceGroup;
    }
//</editor-fold>//GEN-END:|116-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: unidadeOutTemperaturaChoiceGroup ">//GEN-BEGIN:|126-getter|0|126-preInit
    /**
     * Returns an initialized instance of unidadeOutTemperaturaChoiceGroup
     * component.
     *
     * @return the initialized component instance
     */
    public ChoiceGroup getUnidadeOutTemperaturaChoiceGroup() {
        if (unidadeOutTemperaturaChoiceGroup == null) {//GEN-END:|126-getter|0|126-preInit
            // write pre-init user code here
            unidadeOutTemperaturaChoiceGroup = new ChoiceGroup("Unidade de Sa\u00EDda Temperatura", Choice.EXCLUSIVE);//GEN-BEGIN:|126-getter|1|126-postInit
            unidadeOutTemperaturaChoiceGroup.append("Fahrenheit", null);
            unidadeOutTemperaturaChoiceGroup.append("Kelvin", null);
            unidadeOutTemperaturaChoiceGroup.append("Rankine", null);
            unidadeOutTemperaturaChoiceGroup.append("Celsius", null);
            unidadeOutTemperaturaChoiceGroup.setSelectedFlags(new boolean[]{false, false, false, false});//GEN-END:|126-getter|1|126-postInit
            // write post-init user code here
        }//GEN-BEGIN:|126-getter|2|
        return unidadeOutTemperaturaChoiceGroup;
    }
//</editor-fold>//GEN-END:|126-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: formRange ">//GEN-BEGIN:|131-getter|0|131-preInit
    /**
     * Returns an initialized instance of formRange component.
     *
     * @return the initialized component instance
     */
    public Form getFormRange() {
        if (formRange == null) {//GEN-END:|131-getter|0|131-preInit
            // write pre-init user code here
            formRange = new Form("Calculadora de Range", new Item[]{getValorRangeTextField(), getValorRangeInferiorTextField(), getValorRangeSuperiorTextField(), getResultadoAmperStringItem(), getResultadoPsiStringItem()});//GEN-BEGIN:|131-getter|1|131-postInit
            formRange.addCommand(getRangeExitCommand());
            formRange.addCommand(getCalcularCommand());
            formRange.addCommand(getLimparCommand());
            formRange.setCommandListener(this);//GEN-END:|131-getter|1|131-postInit
            // write post-init user code here
            formRange.setItemStateListener(this);
        }//GEN-BEGIN:|131-getter|2|
        return formRange;
    }
//</editor-fold>//GEN-END:|131-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: rangeExitCommand ">//GEN-BEGIN:|132-getter|0|132-preInit
    /**
     * Returns an initialized instance of rangeExitCommand component.
     *
     * @return the initialized component instance
     */
    public Command getRangeExitCommand() {
        if (rangeExitCommand == null) {//GEN-END:|132-getter|0|132-preInit
            // write pre-init user code here
            rangeExitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|132-getter|1|132-postInit
            // write post-init user code here
        }//GEN-BEGIN:|132-getter|2|
        return rangeExitCommand;
    }
//</editor-fold>//GEN-END:|132-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: rangeCommand ">//GEN-BEGIN:|135-getter|0|135-preInit
    /**
     * Returns an initialized instance of rangeCommand component.
     *
     * @return the initialized component instance
     */
    public Command getRangeCommand() {
        if (rangeCommand == null) {//GEN-END:|135-getter|0|135-preInit
            // write pre-init user code here
            rangeCommand = new Command("Range", Command.ITEM, 0);//GEN-LINE:|135-getter|1|135-postInit
            // write post-init user code here
        }//GEN-BEGIN:|135-getter|2|
        return rangeCommand;
    }
//</editor-fold>//GEN-END:|135-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: calcularCommand ">//GEN-BEGIN:|143-getter|0|143-preInit
    /**
     * Returns an initialized instance of calcularCommand component.
     *
     * @return the initialized component instance
     */
    public Command getCalcularCommand() {
        if (calcularCommand == null) {//GEN-END:|143-getter|0|143-preInit
            // write pre-init user code here
            calcularCommand = new Command("Calcular", Command.ITEM, 0);//GEN-LINE:|143-getter|1|143-postInit
            // write post-init user code here
        }//GEN-BEGIN:|143-getter|2|
        return calcularCommand;
    }
//</editor-fold>//GEN-END:|143-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: limparCommand ">//GEN-BEGIN:|145-getter|0|145-preInit
    /**
     * Returns an initialized instance of limparCommand component.
     *
     * @return the initialized component instance
     */
    public Command getLimparCommand() {
        if (limparCommand == null) {//GEN-END:|145-getter|0|145-preInit
            // write pre-init user code here
            limparCommand = new Command("Limpar", Command.ITEM, 0);//GEN-LINE:|145-getter|1|145-postInit
            // write post-init user code here
        }//GEN-BEGIN:|145-getter|2|
        return limparCommand;
    }
//</editor-fold>//GEN-END:|145-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: valorRangeTextField ">//GEN-BEGIN:|138-getter|0|138-preInit
    /**
     * Returns an initialized instance of valorRangeTextField component.
     *
     * @return the initialized component instance
     */
    public TextField getValorRangeTextField() {
        if (valorRangeTextField == null) {//GEN-END:|138-getter|0|138-preInit
            // write pre-init user code here
            valorRangeTextField = new TextField("Valor de Indica\u00E7\u00E3o", "", 32, TextField.DECIMAL);//GEN-LINE:|138-getter|1|138-postInit
            // write post-init user code here
        }//GEN-BEGIN:|138-getter|2|
        return valorRangeTextField;
    }
//</editor-fold>//GEN-END:|138-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: valorRangeInferiorTextField ">//GEN-BEGIN:|139-getter|0|139-preInit
    /**
     * Returns an initialized instance of valorRangeInferiorTextField component.
     *
     * @return the initialized component instance
     */
    public TextField getValorRangeInferiorTextField() {
        if (valorRangeInferiorTextField == null) {//GEN-END:|139-getter|0|139-preInit
            // write pre-init user code here
            valorRangeInferiorTextField = new TextField("Valor Inferior", "", 32, TextField.DECIMAL);//GEN-LINE:|139-getter|1|139-postInit
            // write post-init user code here
        }//GEN-BEGIN:|139-getter|2|
        return valorRangeInferiorTextField;
    }
//</editor-fold>//GEN-END:|139-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: valorRangeSuperiorTextField ">//GEN-BEGIN:|140-getter|0|140-preInit
    /**
     * Returns an initialized instance of valorRangeSuperiorTextField component.
     *
     * @return the initialized component instance
     */
    public TextField getValorRangeSuperiorTextField() {
        if (valorRangeSuperiorTextField == null) {//GEN-END:|140-getter|0|140-preInit
            // write pre-init user code here
            valorRangeSuperiorTextField = new TextField("Valor Superior", "", 32, TextField.DECIMAL);//GEN-LINE:|140-getter|1|140-postInit
            // write post-init user code here
        }//GEN-BEGIN:|140-getter|2|
        return valorRangeSuperiorTextField;
    }
//</editor-fold>//GEN-END:|140-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: resultadoAmperStringItem ">//GEN-BEGIN:|141-getter|0|141-preInit
    /**
     * Returns an initialized instance of resultadoAmperStringItem component.
     *
     * @return the initialized component instance
     */
    public StringItem getResultadoAmperStringItem() {
        if (resultadoAmperStringItem == null) {//GEN-END:|141-getter|0|141-preInit
            // write pre-init user code here
            resultadoAmperStringItem = new StringItem("Resultado de 4 ~ 20 mA", "");//GEN-LINE:|141-getter|1|141-postInit
            // write post-init user code here
        }//GEN-BEGIN:|141-getter|2|
        return resultadoAmperStringItem;
    }
//</editor-fold>//GEN-END:|141-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: resultadoPsiStringItem ">//GEN-BEGIN:|142-getter|0|142-preInit
    /**
     * Returns an initialized instance of resultadoPsiStringItem component.
     *
     * @return the initialized component instance
     */
    public StringItem getResultadoPsiStringItem() {
        if (resultadoPsiStringItem == null) {//GEN-END:|142-getter|0|142-preInit
            // write pre-init user code here
            resultadoPsiStringItem = new StringItem("Resultado de 3 ~ 15 Psi", "");//GEN-LINE:|142-getter|1|142-postInit
            // write post-init user code here
        }//GEN-BEGIN:|142-getter|2|
        return resultadoPsiStringItem;
    }
//</editor-fold>//GEN-END:|142-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|149-getter|0|149-preInit
    /**
     * Returns an initialized instance of stringItem component.
     *
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|149-getter|0|149-preInit
            // write pre-init user code here
            stringItem = new StringItem("", "O MobileInstrumento \u00E9 um aplicativo Java ME que converte vari\u00E1veis de processos industriais (press\u00E3o e temperatura). E tamb\u00E9m faz o c\u00E1lculo de range de 4 mA \u00E0 20 mA ou 3 psi \u00E0 15 psi, mostrando com valor calculado para compara\u00E7\u00E3o.");//GEN-LINE:|149-getter|1|149-postInit
            // write post-init user code here
        }//GEN-BEGIN:|149-getter|2|
        return stringItem;
    }
//</editor-fold>//GEN-END:|149-getter|2|

    /**
     * Returns a display instance.
     *
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started. Checks whether the MIDlet have been
     * already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     *
     * @param unconditional if true, then the MIDlet has to be unconditionally
     * terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
}
